package cn.mapper;

import cn.entity.SysResource;
import cn.entity.SysRole;
import cn.entity.SysUser;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface SysRoleMapper extends Mapper<SysRole> {
    @SelectProvider(type = SysRoleSqlProvider.class,method = "selectPage")
    List<SysRole> selectPage(Map<String,Object> map);

    @SelectProvider(type =SysRoleSqlProvider.class,method = "selectFromRole")
    List<SysRole> selectFromRole(Long id);

    @Select("SELECT id,name FROM sys_user s WHERE s.office_id=#{oid} and not EXISTS (SELECT 1 FROM sys_user_role su WHERE s.office_id =#{oid} and su.role_id=#{uid} and s.id=su.user_id)")
    List<SysUser> selectElse(@Param("uid") Long uid, @Param("oid")Long oid);

    @InsertProvider(type =SysRoleSqlProvider.class, method = "addBtnSubmit")
    int addBtnSubmit(@Param("rid")Long rid, @Param("uids")List<Long> uids);

    @DeleteProvider(type =SysRoleSqlProvider.class, method = "removeBtnSubmit")
    int removeBtnSubmit(@Param("rid")Long rid, @Param("uids") List<Long> uids);

    @Delete("delete from sys_role_resource where role_id =#{id}")
    int deleteBatchResource(Long id);

    @InsertProvider(type =SysRoleSqlProvider.class, method = "insertBatchResource")
    int insertBatchResource(@Param("id")Long id, @Param("newResourcesId")List<Long> newResourcesId);

    @Delete("delete from sys_role_office where role_id =#{id}")
    int deleteBatchOffice(Long id);

    @InsertProvider(type =SysRoleSqlProvider.class, method = "insertBatchOffice")
    int insertBatchOffice(@Param("id")Long id, @Param("newOfficeId")List<Long> newOfficeId);

    @Select("SELECT office_id FROM sys_role_office WHERE role_id =#{rid}")
    List<Long> selectOfficeByRid(Long rid);
}